package cn.wolfcode.p2p.base.service.impl;

import cn.wolfcode.p2p.base.domain.LoginInfo;
import cn.wolfcode.p2p.base.mapper.LoginInfoMapper;
import cn.wolfcode.p2p.base.service.ILoginInfoService;
import cn.wolfcode.p2p.util.MD5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Service;

@Service
public class InitAdminService implements ApplicationListener<ContextRefreshedEvent> {
        @Autowired
        private LoginInfoMapper loginInfoMapper;
        @Override
        public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {

                if(loginInfoMapper.selectCount("admin")>0){
                        return; //如果已经有管理员的账户了,就结束方法
                }
                LoginInfo loginInfo = new LoginInfo();
                loginInfo.setUsername("admin");
                loginInfo.setPassword(MD5.encode("111111"+"admin"));
                loginInfo.setUserType(LoginInfo.TYPE_MGRSITE);
                loginInfoMapper.insert(loginInfo);



        }
}
